package com.ruoyi.dict.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.dict.mapper.TDictUrgencyLevelMapper;
import com.ruoyi.dict.domain.TDictUrgencyLevel;
import com.ruoyi.dict.service.ITDictUrgencyLevelService;
import com.ruoyi.dict.service.IDictUsageCheckService;
import com.ruoyi.common.exception.ServiceException;

/**
 * 紧急程度Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-09-24
 */
@Service
public class TDictUrgencyLevelServiceImpl implements ITDictUrgencyLevelService 
{
    @Autowired
    private TDictUrgencyLevelMapper tDictUrgencyLevelMapper;
    
    @Autowired
    private IDictUsageCheckService dictUsageCheckService;

    /**
     * 查询紧急程度
     * 
     * @param code 紧急程度主键
     * @return 紧急程度
     */
    @Override
    public TDictUrgencyLevel selectTDictUrgencyLevelByCode(String code)
    {
        return tDictUrgencyLevelMapper.selectTDictUrgencyLevelByCode(code);
    }

    /**
     * 查询紧急程度列表
     * 
     * @param tDictUrgencyLevel 紧急程度
     * @return 紧急程度
     */
    @Override
    public List<TDictUrgencyLevel> selectTDictUrgencyLevelList(TDictUrgencyLevel tDictUrgencyLevel)
    {
        return tDictUrgencyLevelMapper.selectTDictUrgencyLevelList(tDictUrgencyLevel);
    }

    /**
     * 新增紧急程度
     * 
     * @param tDictUrgencyLevel 紧急程度
     * @return 结果
     */
    @Override
    public int insertTDictUrgencyLevel(TDictUrgencyLevel tDictUrgencyLevel)
    {
        return tDictUrgencyLevelMapper.insertTDictUrgencyLevel(tDictUrgencyLevel);
    }

    /**
     * 修改紧急程度
     * 
     * @param tDictUrgencyLevel 紧急程度
     * @return 结果
     */
    @Override
    public int updateTDictUrgencyLevel(TDictUrgencyLevel tDictUrgencyLevel)
    {
        return tDictUrgencyLevelMapper.updateTDictUrgencyLevel(tDictUrgencyLevel);
    }

    /**
     * 批量删除紧急程度
     * 
     * @param codes 需要删除的紧急程度主键
     * @return 结果
     */
    @Override
    public int deleteTDictUrgencyLevelByCodes(String[] codes)
    {
        // 检查每个紧急程度是否被使用
        for (String code : codes) {
            if (dictUsageCheckService.isUrgencyLevelInUse(code)) {
                String description = dictUsageCheckService.getUrgencyLevelUsageDescription(code);
                throw new ServiceException(description);
            }
        }
        return tDictUrgencyLevelMapper.deleteTDictUrgencyLevelByCodes(codes);
    }

    /**
     * 删除紧急程度信息
     * 
     * @param code 紧急程度主键
     * @return 结果
     */
    @Override
    public int deleteTDictUrgencyLevelByCode(String code)
    {
        // 检查紧急程度是否被使用
        if (dictUsageCheckService.isUrgencyLevelInUse(code)) {
            String description = dictUsageCheckService.getUrgencyLevelUsageDescription(code);
            throw new ServiceException(description);
        }
        return tDictUrgencyLevelMapper.deleteTDictUrgencyLevelByCode(code);
    }
}